from sqlalchemy import Column, DateTime, String, create_engine, func, text
from sqlalchemy.dialects.mysql import INTEGER
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

from forward.config import get_settings

database_url = get_settings().database_url
engine = create_engine(database_url)
Session = sessionmaker(bind=engine)
session = Session()

# 数据库模型基类
Base = declarative_base()


# class BaseModel(Base):
#     __abstract__ = True


class RecordeMixinModel:

    created_time = Column(DateTime, default=func.now(), comment="创建时间")
    updated_time = Column(
        DateTime, default=func.now(), onupdate=func.now(), comment="更新时间"
    )
    deleted_time = Column(DateTime, comment="删除时间")
    created_by = Column(String(32), comment="创建者")
    updated_by = Column(String(32), comment="更新者")
    deleted_by = Column(String(32), comment="删除者")
    is_deleted = Column(INTEGER(11), server_default=text("0"), comment="是否删除")
